package br.trainee.web.vo;

import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.Lob;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.PrimaryKeyJoinColumn;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

@Entity
@DiscriminatorValue("C")
@PrimaryKeyJoinColumn(name="id_clinica", referencedColumnName="id_pessoa")
@Table(name="clinica")
@NamedQueries(value={
		
		@NamedQuery(name="queryBuscarClinicaPorNome",query="select c from ClinicaVO c where lower(c.nomePessoa) like :nome"),
		@NamedQuery(name="queryBuscarClinicaPorCnpj",query="select c.idPessoa, c.nomePessoa from ClinicaVO c where trim(c.cnpj)=:cnpj"),
		@NamedQuery(name="queryBuscarTodasClincas", query="select c from ClinicaVO c"),
		@NamedQuery(name="queryBuscarClinicaPorNomeECnpj", query="select c from ClinicaVO c where (:nome is null or lower(c.nomePessoa) like :nome) "
				+ "and (:cnpj is null or trim(c.cnpj)= :cnpj) and c.statusPessoa.tipoStatus=:tipoStatus")
		
})
public class ClinicaVO extends PessoaVO{
	

	/*@Column(name="nome_clinica")
	private String nomeClinica;*/
	
	@Column(name="cnpj")
	private String cnpj;
	
	@Lob
	@Column(name="foto_clinica")
	private byte[] fotoClinica;
	
	/*@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="id_status",referencedColumnName="id_status")
	private StatusVO status;*/
	
	@OneToMany(fetch=FetchType.LAZY, mappedBy="clinica",cascade={CascadeType.PERSIST,CascadeType.REMOVE})
	private List<EnderecoClinicaVO> enderecos;
	
	@OneToMany(mappedBy="clinica", fetch=FetchType.LAZY, cascade={CascadeType.REMOVE})
	private List<ClinicaTelefoneClinicaVO> listaClinicaTelefone;
	
	@Temporal(TemporalType.DATE)
	@Column(name="data_abertura")
	private Date dataAbertura;
	
	@Transient
	private List<TelefoneClinicaVO> listaTelefones;
	
	@Transient
	private List<EmailClinicaVO> listaEmailAuxInc;
	
	@Transient
	private List<EmailClinicaVO> listaEmailAuxExc;
	
	@Transient
	private List<EnderecoClinicaVO> listaEnderecoAuxInc;
	
	@Transient
	private List<EnderecoClinicaVO> listaEnderecoAuxExc;
	
	@Transient
	private List<TelefoneClinicaVO> listaTelefoneAuxInc;
	
	@Transient
	private List<TelefoneClinicaVO> listaTelefoneAuxExc;
	
	/*
	 * FORMA ERRADA DE RELACIONAMENTO N,N
	 * 
	@JoinTable(name="clinica_telefone_clinica",joinColumns={
			@JoinColumn(name="id_clinica", referencedColumnName="id_clinica")
	}, inverseJoinColumns={
			@JoinColumn(name="id_telefone_clinica", referencedColumnName="id_telefone_clinica")
	})
	@ManyToMany(fetch=FetchType.LAZY)
	private List<TelefoneClinicaVO> telefones;
	*/
	/*
	@OneToMany(fetch=FetchType.LAZY, mappedBy="clinica", cascade={CascadeType.PERSIST,CascadeType.REMOVE,CascadeType.MERGE})
	private List<TelefoneClinicaVO> telefones;
	*/
	
	@OneToMany(fetch=FetchType.LAZY, mappedBy="clinica", cascade={CascadeType.PERSIST,CascadeType.REMOVE})
	private List<EmailClinicaVO> emails;
	
	
	public ClinicaVO() {
		
		
		
	}
	


	public byte[] getFotoClinica() {
		return fotoClinica;
	}
	public void setFotoClinica(byte[] fotoClinica) {
		this.fotoClinica = fotoClinica;
	}


	public List<EnderecoClinicaVO> getEnderecos() {
		return enderecos;
	}
	public void setEnderecos(List<EnderecoClinicaVO> enderecos) {
		this.enderecos = enderecos;
	}

	
	public List<ClinicaTelefoneClinicaVO> getListaClinicaTelefone() {
		return listaClinicaTelefone;
	}
	public void setListaClinicaTelefone(
			List<ClinicaTelefoneClinicaVO> listaClinicaTelefone) {
		this.listaClinicaTelefone = listaClinicaTelefone;
	}
	

	public List<EmailClinicaVO> getEmails() {
		return emails;
	}
	public void setEmails(List<EmailClinicaVO> emails) {
		this.emails = emails;
	}
	
	
	public String getCnpj() {
		return cnpj;
	}
	public void setCnpj(String cnpj) {
		this.cnpj = cnpj;
	}
	

	public List<TelefoneClinicaVO> getListaTelefones() {
		return listaTelefones;
	}
	public void setListaTelefones(List<TelefoneClinicaVO> listaTelefones) {
		this.listaTelefones = listaTelefones;
	}


	public List<EmailClinicaVO> getListaEmailAuxInc() {
		return listaEmailAuxInc;
	}
	public void setListaEmailAuxInc(List<EmailClinicaVO> listaEmailAuxInc) {
		this.listaEmailAuxInc = listaEmailAuxInc;
	}


	public List<EmailClinicaVO> getListaEmailAuxExc() {
		return listaEmailAuxExc;
	}
	public void setListaEmailAuxExc(List<EmailClinicaVO> listaEmailAuxExc) {
		this.listaEmailAuxExc = listaEmailAuxExc;
	}


	public List<EnderecoClinicaVO> getListaEnderecoAuxInc() {
		return listaEnderecoAuxInc;
	}
	public void setListaEnderecoAuxInc(List<EnderecoClinicaVO> listaEnderecoAuxInc) {
		this.listaEnderecoAuxInc = listaEnderecoAuxInc;
	}


	public List<EnderecoClinicaVO> getListaEnderecoAuxExc() {
		return listaEnderecoAuxExc;
	}
	public void setListaEnderecoAuxExc(List<EnderecoClinicaVO> listaEnderecoAuxExc) {
		this.listaEnderecoAuxExc = listaEnderecoAuxExc;
	}



	public List<TelefoneClinicaVO> getListaTelefoneAuxInc() {
		return listaTelefoneAuxInc;
	}



	public void setListaTelefoneAuxInc(List<TelefoneClinicaVO> listaTelefoneAuxInc) {
		this.listaTelefoneAuxInc = listaTelefoneAuxInc;
	}



	public List<TelefoneClinicaVO> getListaTelefoneAuxExc() {
		return listaTelefoneAuxExc;
	}



	public void setListaTelefoneAuxExc(List<TelefoneClinicaVO> listaTelefoneAuxExc) {
		this.listaTelefoneAuxExc = listaTelefoneAuxExc;
	}



	public Date getDataAbertura() {
		return dataAbertura;
	}



	public void setDataAbertura(Date dataAbertura) {
		this.dataAbertura = dataAbertura;
	}
	
	
	
}
